/**
 * 
 */
package jmine.tec.subscription.impl;

import jmine.tec.subscription.Publication;
import jmine.tec.subscription.PublicationListener;
import jmine.tec.subscription.Publisher;
import jmine.tec.subscription.SubscriptionSettings;

/**
 * {@link PublicationListener} que 'empurra' para um {@link SubscriptionSetImpl}
 * 
 * @author takeshi
 * @param <P> o tipo da {@link Publication}
 */
public final class PushPublicationListener<P extends Publication> implements PublicationListener<P> {

    private final SubscriptionImpl subscription;

    private final SubscriptionSetImpl queueSubscriptionSet;

    /**
     * C'tor
     * 
     * @param e {@link SubscriptionImpl}
     * @param queueSubscriptionSet {@link SubscriptionSetImpl}
     */
    public PushPublicationListener(SubscriptionImpl e, SubscriptionSetImpl queueSubscriptionSet) {
        this.subscription = e;
        this.queueSubscriptionSet = queueSubscriptionSet;
    }

    /**
     * @return <code>false</code>
     */
    public boolean isTransactionRequired() {
        return false;
    }

    /**
     * {@inheritDoc}
     */
    public void onPublication(Publisher<P> publisher, SubscriptionSettings settings, P publication) {
        this.queueSubscriptionSet.publish(publication, this.subscription);
    }

    /**
     * {@inheritDoc}
     */
    public boolean isAssynchronous() {
        return false;
    }
}